package applet.swing;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import javax.swing.JTextField;

class SwingEvent extends JFrame implements ActionListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	JLabel label0;
	JLabel label1;
	JLabel label2;
	JTextField textField;
	JPasswordField pswdField;
	JButton button1;
	JButton button2;

	SwingEvent() {
		// Defining the layout
		this.setLayout(null);

		// Define the components
		label0 = new JLabel("Login");
		label1 = new JLabel("Username");
		label2 = new JLabel("Password");
		textField = new JTextField();
		pswdField = new JPasswordField();
		button1 = new JButton("Submit");
		button2 = new JButton("Reset");

		// Set boundary
		label0.setBounds(110, 5, 90, 30);
		label1.setBounds(60, 35, 90, 30);
		label2.setBounds(60, 65, 90, 30);
		textField.setBounds(160, 35, 90, 30);
		pswdField.setBounds(160, 65, 90, 30);
		button1.setBounds(60, 100, 90, 30);
		button2.setBounds(160, 100, 90, 30);

		// Adding the components to the frame
		this.add(label0);
		this.add(label1);
		this.add(textField);
		this.add(label2);
		this.add(pswdField);
		this.add(button1);
		this.add(button2);

		// Register Events
		button1.addActionListener(this);
		button2.addActionListener(this);
	}

	@SuppressWarnings("deprecation")
	public void actionPerformed(ActionEvent ae) {
		String name = ae.getActionCommand();
		if (name.equals("Reset")) {
			textField.setText(null);
			pswdField.setText(null);
		} else if (name.equals("Submit")) {
			String userName = textField.getText();
			String pswd = pswdField.getText();
			if (pswd.equals("123") && userName.equals("abc"))
				JOptionPane.showMessageDialog(this, "Success");
			else
				JOptionPane.showMessageDialog(this, "failure");
		}
	}

	public static void main(String args[]) {
		SwingEvent obj = new SwingEvent();
		obj.setVisible(true);
		obj.setSize(300, 200);
		obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}
